//https://leetcode.cn/problems/kth-node-from-end-of-list-lcci/description/

int kthToLast(struct ListNode* head, int k) {

    if (head == NULL)
    {
        return NULL;
    }

    struct ListNode* slow, * fast;
    slow = fast = head;

    while (k--)
    {
        if (fast == NULL)
        {
            return NULL;
        }
        fast = fast->next;
    }

    while (fast)
    {
        slow = slow->next;
        fast = fast->next;
    }

    return slow->val;

}
